package com.bstek.bdf4.investigate;

import com.bstek.bdf4.investigate.entity.Category;
import com.bstek.bdf4.investigate.service.CategoryService;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.data.provider.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;

@Component
public class CategoryProvider {
    @Autowired
    private CategoryService categoryService;

    @DataProvider
    public Collection<Category> getCategoryById(Long id) {
        return categoryService.getCategoryById(id);
    }

    @DataProvider
    public Collection<Category> getTopCategories() {
        return categoryService.getTopAll();
    }

    @DataProvider
    public void getAllCategories(Page<Category> page) {
        categoryService.getAllCategories(page);
    }

    @DataResolver
    @Transactional
    public void save(Collection<Category> categoryList) {
        categoryService.save(categoryList);
    }
}
